package work;

import com.mchange.v2.c3p0.ComboPooledDataSource;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;

public class C3P0Utils {
    //构造工具类C3P0连接池
        //连接池对象
        private static ComboPooledDataSource dataSource = new ComboPooledDataSource();
        /**
         * 获得数据源(连接池)
         * @return
         */
        public static DataSource getDataSource(){
            return dataSource;
        }
        /**
         * 获得连接
         * @return
         */
        public static Connection getConnection(){
            //将从连接池中获得连接对象
            try {
                return dataSource.getConnection();
            } catch (SQLException e) {
                e.printStackTrace();
            }
            return null;
        }

}
